<%--
  Created by IntelliJ IDEA.
  User: You
  Date: 2020/5/20
  Time: 11:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*,com.xingyun.info_manager.entity.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title></title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
</head>
<div class="layui-container">
    <div class="layui-row">
        <div class="layui-col-lg12">
            <%--<fieldset class="layui-elem-field">--%>
                <%--<legend>编辑用户</legend>--%>
                <div class="layui-field-box">
                    <form id="formAdd" class="layui-form " action="">
                        <input type="hidden" id="patId" name="id" value="${patientInfo.id}" >
                        <div class="layui-form-item">
                            <div class="layui-col-sm3">
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 60px;text-align: left;">姓名<span style="color: red">*</span></label>
                                    <div class="layui-input-inline" style="width: 150px;">
                                        <input type="text" name="patName" required lay-verify="required" value="${patientInfo.patName}"  class="layui-input">
                                    </div>
                                    <%--<div class="layui-form-mid layui-word-aux">辅助文字</div>--%>
                                </div>
                            </div>
                            <div class="layui-col-sm3">
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 60px;text-align: left;">年龄</label>
                                    <div class="layui-input-inline" style="width: 150px;">
                                        <input type="text" name="age" value="${patientInfo.age}" lay-verify="number" autocomplete="off" class="layui-input">
                                    </div>
                                    <%--<div class="layui-form-mid layui-word-aux">辅助文字</div>--%>
                                </div>
                            </div>
                            <div class="layui-col-sm3">
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 60px;text-align: left;">手机号<span style="color: red">*</span></label>
                                    <div class="layui-input-inline" style="width: 150px;">
                                        <input type="text" id="phone" name="phone" lay-verify="phone" value="${patientInfo.phone}"  class="layui-input">
                                    </div>
                                    <%--<div class="layui-form-mid layui-word-aux">辅助文字</div>--%>
                                </div>
                            </div>
                            <div class="layui-col-sm3">
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 60px;text-align: left;">微信号<span style="color: red">*</span></label>
                                    <div class="layui-input-inline" style="width: 150px;">
                                        <input type="text" name="wechat" value="${patientInfo.wechat}"  class="layui-input">
                                    </div>
                                    <%--<div class="layui-form-mid layui-word-aux">辅助文字</div>--%>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-col-sm3">
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 60px;text-align: left;">性别</label>
                                    <div class="layui-input-inline" style="width: 150px;">
                                        <select name="gender" >
                                            <option value="1" <c:if test="${patientInfo.gender == 1}">selected</c:if>>男</option>
                                            <option value="2" <c:if test="${patientInfo.gender == 2}">selected</c:if>>女</option>
                                        </select>
                                    </div>
                                    <%--<div class="layui-form-mid layui-word-aux">辅助文字</div>--%>
                                </div>
                            </div>
                            <div class="layui-col-sm3">
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 60px;text-align: left;">是否来院</label>
                                    <div class="layui-input-inline" style="width: 150px;">
                                        <select name="isComeHospital" >
                                            <option value="9" <c:if test="${patientInfo.isComeHospital == 9}">selected</c:if>>请选择</option>
                                            <option value="1" <c:if test="${patientInfo.isComeHospital == 1}">selected</c:if>>是</option>
                                            <option value="2" <c:if test="${patientInfo.isComeHospital == 2}">selected</c:if>>否</option>
                                        </select>
                                    </div>
                                    <%--<div class="layui-form-mid layui-word-aux">辅助文字</div>--%>
                                </div>
                            </div>
                            <div class="layui-col-sm3">
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 60px;text-align: left;">预约科室</label>
                                    <div class="layui-input-inline" style="width: 150px;">
                                        <input type="text" name="appointDept" value="${patientInfo.appointDept}"  class="layui-input">
                                    </div>
                                    <%--<div class="layui-form-mid layui-word-aux">辅助文字</div>--%>
                                </div>
                            </div>
                            <div class="layui-col-sm3">
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 60px;text-align: left;">病种</label>
                                    <div class="layui-input-inline" style="width: 150px;">
                                        <input type="text" name="diseaseEntities" value="${patientInfo.diseaseEntities}"  class="layui-input">
                                    </div>
                                    <%--<div class="layui-form-mid layui-word-aux">辅助文字</div>--%>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-col-sm3">
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 60px;text-align: left;">咨询方式</label>
                                    <div class="layui-input-inline" style="width: 150px;">
                                        <select name="consultType" lay-verify="required">
                                            <option value="9" <c:if test="${patientInfo.consultType == 9}">selected</c:if>>请选择</option>
                                            <option value="1" <c:if test="${patientInfo.consultType == 1}">selected</c:if>>商务通</option>
                                            <option value="2" <c:if test="${patientInfo.consultType == 2}">selected</c:if>>电话</option>
                                            <option value="3" <c:if test="${patientInfo.consultType == 3}">selected</c:if>>市场电话</option>
                                            <option value="4" <c:if test="${patientInfo.consultType == 4}">selected</c:if>>商转微</option>
                                            <option value="5" <c:if test="${patientInfo.consultType == 5}">selected</c:if>>微信</option>
                                        </select>
                                    </div>
                                    <%--<div class="layui-form-mid layui-word-aux">辅助文字</div>--%>
                                </div>
                            </div>
                            <div class="layui-col-sm3">
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 60px;text-align: left;">预约时间</label>
                                    <div class="layui-input-inline" style="width: 150px;">
                                        <input type="text" name="appointTime" value="<fmt:formatDate value="${patientInfo.appointTime}" pattern="yyyy-MM-dd"/>" class="layui-input" id="date1">
                                    </div>
                                    <%--<div class="layui-form-mid layui-word-aux">辅助文字</div>--%>
                                </div>
                            </div>
                            <div class="layui-col-sm3">
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 60px;text-align: left;">接诊医生</label>
                                    <div class="layui-input-inline" style="width: 150px;">
                                        <input type="text" name="attendDoctor" value="${patientInfo.attendDoctor}"  class="layui-input">
                                    </div>
                                    <%--<div class="layui-form-mid layui-word-aux">辅助文字</div>--%>
                                </div>
                            </div>
                            <div class="layui-col-sm3">
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 60px;text-align: left;">是否复诊</label>
                                    <div class="layui-input-inline" style="width: 150px;">
                                        <select name="subsequentVisit" >
                                            <option value="9" <c:if test="${patientInfo.subsequentVisit == 9}">selected</c:if>>请选择</option>
                                            <option value="1" <c:if test="${patientInfo.subsequentVisit == 1}">selected</c:if>>是</option>
                                            <option value="2" <c:if test="${patientInfo.subsequentVisit == 2}">selected</c:if>>否</option>
                                        </select>
                                    </div>
                                    <%--<div class="layui-form-mid layui-word-aux">辅助文字</div>--%>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-col-sm3">
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 60px;text-align: left;">治疗项目</label>
                                    <div class="layui-input-inline" style="width: 150px;">
                                        <input type="text" name="treatmentItems" value="${patientInfo.treatmentItems}"  class="layui-input">
                                    </div>
                                    <%--<div class="layui-form-mid layui-word-aux">辅助文字</div>--%>
                                </div>
                            </div>
                            <div class="layui-col-sm3">
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 60px;text-align: left;">是否住院</label>
                                    <div class="layui-input-inline" style="width: 150px;">
                                        <select name="isInHospital">
                                            <option value="9" <c:if test="${patientInfo.isInHospital == 9}">selected</c:if>>请选择</option>
                                            <option value="1" <c:if test="${patientInfo.isInHospital == 1}">selected</c:if>>是</option>
                                            <option value="2" <c:if test="${patientInfo.isInHospital == 2}">selected</c:if>>否</option>
                                        </select>
                                    </div>
                                    <%--<div class="layui-form-mid layui-word-aux">辅助文字</div>--%>
                                </div>
                            </div>
                            <div class="layui-col-sm3">
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 60px;text-align: left;">消费金额</label>
                                    <div class="layui-input-inline" style="width: 150px;">
                                        <input type="text" name="totalMoney" value="${patientInfo.totalMoney}"  class="layui-input">
                                    </div>
                                    <%--<div class="layui-form-mid layui-word-aux">辅助文字</div>--%>
                                </div>
                            </div>
                            <div class="layui-col-sm3">
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 60px;text-align: left;">是否回访</label>
                                    <div class="layui-input-inline" style="width: 150px;">
                                        <select name="returnVisit">
                                            <option value="9" <c:if test="${patientInfo.returnVisit == 9}">selected</c:if>>请选择</option>
                                            <option value="1" <c:if test="${patientInfo.returnVisit == 1}">selected</c:if>>是</option>
                                            <option value="2" <c:if test="${patientInfo.returnVisit == 2}">selected</c:if>>否</option>
                                        </select>
                                    </div>
                                    <%--<div class="layui-form-mid layui-word-aux">辅助文字</div>--%>
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-col-sm4">
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 60px;text-align: left;">患者情况:</label>
                                    <div class="layui-input-inline" style="width: 300px;">
                                        <textarea name="patSituation" id="testarea" class="layui-textarea">${patientInfo.patSituation}</textarea>
                                    </div>
                                    <%--<div class="layui-form-mid layui-word-aux">辅助文字</div>--%>
                                </div>
                            </div>

                            <div class="layui-col-sm4">
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 60px;text-align: left;">患者意向:</label>
                                    <div class="layui-input-inline" style="width: 300px;">
                                        <textarea name="patIntention" class="layui-textarea">${patientInfo.patIntention}</textarea>
                                    </div>
                                    <%--<div class="layui-form-mid layui-word-aux">辅助文字</div>--%>
                                </div>
                            </div>
                            <div class="layui-col-sm4">
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 120px;text-align: left;">未到院回访情况:</label>
                                    <div class="layui-input-inline" style="width: 300px;">
                                        <textarea name="notComeReason" class="layui-textarea">${patientInfo.notComeReason}</textarea>
                                    </div>
                                    <%--<div class="layui-form-mid layui-word-aux">辅助文字</div>--%>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item" style="margin-left: 465px;">
                            <ul >
                                <li style="float:left;">
                                    <div class="" style="">
                                        <button id="commitBtn" class="layui-btn" lay-submit lay-filter="formDemo">提交</button>
                                    </div>
                                </li>
                                <li style="float:left;margin-left: 25px">
                                    <div class="" style="">
                                        <button type="button" id="backBtn" class="layui-btn layui-btn-primary">返回</button>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </form>
                </div>
            <%--</fieldset>--%>
        </div>
    </div>
</div>
<script type="text/javascript" src="${pageContext.request.contextPath}/javascript/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/layui/layui.all.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/javascript/dw_form_submit.js"></script>
<script>

    //时间控件
    var laydate = layui.laydate;

    var startTime = '';
    //执行一个laydate实例
    laydate.render({
        elem: '#date1' //指定元素
        ,format: 'yyyy-MM-dd' //可任意组合

        // ,range: true //或 range: '~' 来自定义分割字符
        // ,done: function(value, date, endDate){
        //     startTime = value;
        //     console.log(value); //得到日期生成的值，如：2017-08-18
        //     // console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
        //     // console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。
        // }
    });
    var form = layui.form;
    // 自定义校验规则
    //这个里面的title、number就写在Html 代码中lay-verify的属性值，即可
    //例如：lay-verify="title"
    // form.verify({
    //     title : function(value) {
    //         if (value.length < 5) {
    //             return '至少输入5个字符啊';
    //         }
    //     },
    //     number : [/^[0-9]*$/, '必须输入数字啊']
    // });

    // 监听提交
    form.on('submit(formDemo)', function(data) {
        var phone = $("#phone").val();
        var id = $("#patId").val();
        if(phone){
            console.log("phone存在:"+phone)
            $.ajax({
                url : '${pageContext.request.contextPath}/patnet/phonemsg?id='+id,//数据接口
                type : 'post',
                contentType: "application/x-www-form-urlencoded",
                dataType : 'json',
                data: {"phone":phone},//转化json格式
                success : function(data) {
                    if(data.code == 1){
                        //弹出框提示
                        layer.msg(data.msg);
                    } else {
                        updateSubmit();
                    }
                }
            });
        } else {
            console.log("phone不存在！")
            updateSubmit();
        }
        return false;
    });
    
    function updateSubmit() {
        $.ajax({
            url : '${pageContext.request.contextPath}/patnet/update',//数据接口
            type : 'post',
            contentType: "application/x-www-form-urlencoded",
            dataType : 'json',
            data: $('#formAdd').serialize(),//转化json格式
            success : function(data) {
                if(data.code == 0){
                    //弹出框提示
                    layer.msg("用户修改成功", {
                        area: '200px',
                        time: 0, //不自动关闭
                        btn: ['确定'],
                        btnAlign: 'c', //按钮居中
                        yes: function(index, layero){
                            //按钮【按钮一】的回调
                            //当你在iframe页面关闭自身时，关闭新增弹出框
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                        }
                    });
                } else {
                    layer.msg(data.msg, {
                        area: '200px',
                        time: 5000, //5s后自动关闭
                        btn: ['确定'],
                        btnAlign: 'c', //按钮居中
                    });
                }
            },
            error:function (data) {
                layer.msg("修改失败", {
                    area: '200px',
                    time: 5000, //5s后自动关闭
                    btn: ['确定'],
                    btnAlign: 'c', //按钮居中
                });
            }
        });
    }
    
    // form.render(); // 更新全部

    <%--修改提交按钮--%>
     <%--$("#commitBtn").click(function () {--%>
         <%--/**--%>
          <%--* 通用表单验证--%>
          <%--*/--%>
         <%--form.verify();--%>

         <%--$.ajax({--%>
             <%--url : '${pageContext.request.contextPath}/admin/update',//数据接口--%>
             <%--type : 'post',--%>
             <%--contentType: "application/x-www-form-urlencoded",--%>
             <%--dataType : 'json',--%>
             <%--data: $('#formAdd').serialize(),//转化json格式--%>
             <%--success : function(data) {--%>
                 <%--if(data.code == 0){--%>
                     <%--//弹出框提示--%>
                     <%--layer.msg("用户修改成功", {--%>
                         <%--area: '200px',--%>
                         <%--time: 0, //不自动关闭--%>
                         <%--btn: ['确定'],--%>
                         <%--btnAlign: 'c', //按钮居中--%>
                         <%--yes: function(index, layero){--%>
                             <%--//按钮【按钮一】的回调--%>
                             <%--//当你在iframe页面关闭自身时，关闭新增弹出框--%>
                             <%--var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引--%>
                             <%--parent.layer.close(index); //再执行关闭--%>
                         <%--}--%>
                     <%--});--%>
                 <%--} else {--%>
                     <%--layer.msg(data.msg, {--%>
                         <%--area: '200px',--%>
                         <%--time: 5000, //5s后自动关闭--%>
                         <%--btn: ['确定'],--%>
                         <%--btnAlign: 'c', //按钮居中--%>
                     <%--});--%>
                 <%--}--%>
             <%--},--%>
             <%--error:function (data) {--%>
                 <%--layer.msg("修改失败", {--%>
                     <%--area: '200px',--%>
                     <%--time: 5000, //5s后自动关闭--%>
                     <%--btn: ['确定'],--%>
                     <%--btnAlign: 'c', //按钮居中--%>
                 <%--});--%>
             <%--}--%>
         <%--});--%>
     <%--})--%>

    /*关闭按钮*/
    $("#backBtn").click(function () {
        //当你在iframe页面关闭自身时，关闭新增弹出框
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭
    })
</script>
</body>
</html>
